﻿using ManagementApi.Models;
using ManagementApi.Models.Device;
using ManagementApi.Mvc;
using ManagementApi.Mvc.ApplicationContexts;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Modules.Device;
using PmSoft.ApplicationContext;

namespace ManagementApi.Controllers.ManagerPannel
{
    /// <summary>
    /// app授权查询
    /// </summary>
    [Route("/api/v1/manager/AppCheckinAuth")]
    [ApiController]
    [Authorize(Roles = "Manager")]
    public class AppCheckinAuthController : ControllerBase
    {
        private readonly AppCheckinAuthService appCheckinAuthService;
        private readonly ProjectManagerApplicationContext applicationContext;

        public AppCheckinAuthController(AppCheckinAuthService appCheckinAuthService, ProjectManagerApplicationContext applicationContext)
        {
            this.appCheckinAuthService = appCheckinAuthService;
            this.applicationContext = applicationContext;
        }

        /// <summary>
        /// App考勤授权分页
        /// </summary>
        /// <param name="query"></param>
        /// <param name="pageNum"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet("page")]
        public ApiResult<PageDto<AppCheckinAuthDto>> GetCorpInfos([FromQuery] AppCheckinAuthQuery query, int pageNum = 1, int pageSize = 20)
        {
            query.ProjectId = applicationContext.CurrentProjectInfo.ProjectId;
            var data = appCheckinAuthService.GetAppCheckinAuths(query, pageNum, pageSize);
            var dtos = data.AsPageDto(source => { return source.AsDto(applicationContext); });
            return ApiResult<PageDto<AppCheckinAuthDto>>.Success(dtos);
        }
    }
}
